﻿using System;
using System.Windows.Forms;
using IceCS.GoodsSale.BLL;
using IceCS.GoodsSale.Models.GoodsModels;

namespace IceCS.GoodsSale.Winform
{
    public partial class FrmInventoryQuery : Form
    {
        public FrmInventoryQuery()
        {
            InitializeComponent();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtGoodsID.Text.Trim() == "")
                {
                    MessageBox.Show("请输入商品号", "提示");
                    txtGoodsID.Focus();
                    return;
                }
                string goodsID = txtGoodsID.Text.Trim();
                GoodsManager goodsManager = new GoodsManager();
                if (!goodsManager.GoodsIsExist(goodsID))
                {
                    txtGoodsID.Text = "商品不存在";
                    txtGoodsID.SelectAll();
                    txtGoodsID.Focus();
                    return;
                }
                Goods goods = goodsManager.GetGoods(goodsID);
                txtName.Text = goods.Name;
                txtInventory.Text = goods.Inventory.ToString();
                btnClear.Focus();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void txtGoodsID_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnQuery_Click(sender, e);
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtGoodsID.Text = "";
            txtName.Text = "";
            txtInventory.Text = "";
            txtGoodsID.Focus();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
